require('./shipping.css');
import {
    setDefaultAddr,
    removeAddr
} from './ajax';



$(function () {


    $('.check').iCheck({
        radioClass: 'iradio_square-blue'
    });


    //设置默认地址
    $('.check').on('ifChecked', function () {
        let addid = $(this).data('addid');
        let referer =decodeURIComponent($(this).data('referer'));
        setDefaultAddr(addid, (res) => {
            if (res.rel != '1') {
                $.toast(res.msg);
                return false;
            }
            if (referer) {
                location.href = referer;
            }

        });
    });

    $('.removeBtn').click(function () {
        let self = this;
        $.confirm('删除此条收货地址？', function () {
            let parElem = $(self).parents('.address-list');
            let addid = $('.check', parElem).data('addid');
            removeAddr(addid, (res) => {
                if (res.rel == 1) {
                    $(parElem).remove();
                } else {
                    $.toast(res.msg);
                }
            });
        });

    });



});